Parent Object

I am trying to set a parent level object attribute based on the values of an attribute in the object text:

for example:

I want to set Heading  attribute "Test Attribute" to "True" if  

Child Object 1 "Test Attribute" == True

I can do this however, I don't know how to do it if there are more than one children object:

Child Object 1 "Test Attribute" == True

Child Object 2 "Test Attribute" == False

In this case if one of the children object is false then it will not be true, Can someone help me understand what I need to use so that I can read all values of children and set the heading based on those values? 

 

 


A_Alers - Mon Oct 20 17:56:46 EDT 2014

Re: Parent Object
Mike.Scharnow - Mon Oct 20 19:53:24 EDT 2014

I understand that by "children" you mean the direct children of the parent object.

You can use the "for object in object" loop for this.

This is what it might look like (just an idea, syntax will not be correct).

Object oParent
for oParent in entire current module do {
if (oParent is not deleted and it is a parent requirement and not a child and not a normal chapter heading) {
    bool bTest_result = true
    Object o
    for o in oParent do {
        if ("False" == o."Test Attribute" "") then bTest_result = false
    }
    oParent."Test Attribute" = bTest_result
}
}



Hope this helps,
Mike

Re: Parent Object
Wolfgang Uhr - Tue Oct 21 08:00:33 EDT 2014

Hi

Object getFirstChild(Object objParent) {
    Object objChild = null;
 for objChild in objParent do {
  return (objChild); 
 }
 return (objChild);
}

 This routine returns null, if the parent object does not have child and it returns the first child if there is one or more childs

Best regards

Wolfgang

Re: Parent Object
A_Alers - Tue Oct 21 19:25:00 EDT 2014

Mike.Scharnow - Mon Oct 20 19:53:24 EDT 2014

I understand that by "children" you mean the direct children of the parent object.

You can use the "for object in object" loop for this.

This is what it might look like (just an idea, syntax will not be correct).

Object oParent
for oParent in entire current module do {
if (oParent is not deleted and it is a parent requirement and not a child and not a normal chapter heading) {
    bool bTest_result = true
    Object o
    for o in oParent do {
        if ("False" == o."Test Attribute" "") then bTest_result = false
    }
    oParent."Test Attribute" = bTest_result
}
}



Hope this helps,
Mike

Hi,

Thank you for your rapid response, I'm sorry I was not specific with my question, this is similar to what I have however, it will not work if I have other options, for example something other than True, or False, if I have a third Object where the attribute is "Test" and I want the Heading level attribute to say "Test", it ignores my condition.  So if I have:

Object 1 = Test

Object 2 = True

Object 3 = True

The heading level attribute will display "True"

But if I had:

Object 1 = True

Object 2 = True

Object 3 = Test

Then the heading level will display "Test"

Re: Parent Object
Mike.Scharnow - Wed Oct 22 04:54:06 EDT 2014

A_Alers - Tue Oct 21 19:25:00 EDT 2014

Hi,

Thank you for your rapid response, I'm sorry I was not specific with my question, this is similar to what I have however, it will not work if I have other options, for example something other than True, or False, if I have a third Object where the attribute is "Test" and I want the Heading level attribute to say "Test", it ignores my condition.  So if I have:

Object 1 = Test

Object 2 = True

Object 3 = True

The heading level attribute will display "True"

But if I had:

Object 1 = True

Object 2 = True

Object 3 = Test

Then the heading level will display "Test"

Well, it seems you need to become clear what logic you want to apply, independent of any programming language, which situations can occur, which result do you expect in these situations?

You need to write this down, perhaps in form of a decision table, then transfer your rules into "if", "then", "elif", "else".

From your description I figure that you set the parent's value with the Test Attribute of the last child

Re: Parent Object
A_Alers - Wed Oct 22 19:05:09 EDT 2014

Mike.Scharnow - Wed Oct 22 04:54:06 EDT 2014

Well, it seems you need to become clear what logic you want to apply, independent of any programming language, which situations can occur, which result do you expect in these situations?

You need to write this down, perhaps in form of a decision table, then transfer your rules into "if", "then", "elif", "else".

From your description I figure that you set the parent's value with the Test Attribute of the last child

Hi,

I did create a decision table, my problem seems to be when I iterate the children objects, I think I am not doing it correctly since it does not work:

if(o."Attribute Test"""=="Test"){
    if(null next sibling o){
         result = "Test"
    }

   else if(!null next sibling o && next sibling o == "False"){
         result = "False"
 }

 else{
    result = "Test"
 }

  For this particular case I want to iterate through all the children, if it contains "Test"  and at least one of it's children is "False" then the heading value will be "False".

 

 

 

 

Re: Parent Object
Mike.Scharnow - Thu Oct 23 02:16:57 EDT 2014

A_Alers - Wed Oct 22 19:05:09 EDT 2014

Hi,

I did create a decision table, my problem seems to be when I iterate the children objects, I think I am not doing it correctly since it does not work:

if(o."Attribute Test"""=="Test"){
    if(null next sibling o){
         result = "Test"
    }

   else if(!null next sibling o && next sibling o == "False"){
         result = "False"
 }

 else{
    result = "Test"
 }

  For this particular case I want to iterate through all the children, if it contains "Test"  and at least one of it's children is "False" then the heading value will be "False".

 

 

 

 

Well, there is one error: Line 6

next sibling o == "False"

should probably be

(next sibling o)."Attribute Test" "" == "False".

But, from this code, I'm not exactly sure what the rules shall be. If you say "one of its children", do you mean "one of its successors"? What you did was to program "if o is "Test", then result is "Test", unless its direct successor is "False".

I could imagine that your idea is something like the following:

Allowed values are "True", "False", "Test" and empty. Empty counts as False

if an object has no child, result is True

If at least one child has "False" this value has the highest precedence, parent value is "False"

If no "False" occurs, check whether one child has "Test". If so, parent value is "Test"

Only if all children are "True" then parent value is "True"

Then you could do a script such as in my first post and replace the inner loop (line 7) with the following

if ("False" == o."Test Attribute""" or "" == o."Test Attribute""") then sTest_result = "False"
if ("False" != sTest_result and "Test" == o."Test Attribute""") then sTest_result = "Test"

Note that the type of the result variable changed from bool to string. The start value of sTest_result must be "True" instead of true.

 

Did I understand you correctly?